package net.sf.midollo.net.protocol.multitunnel.server;

import java.io.IOException;

import net.sf.midollo.io.IOStream;
import net.sf.midollo.io.IOStreamFactory;
import net.sf.midollo.net.protocol.multitunnel.MultiTunnelManager;
import net.sf.midollo.net.protocol.multitunnel.MultiTunnelSession;

public class MultiTunnelServerFactory extends MultiTunnelManager {

  protected final IOStreamFactory serverIOStreamFactory;
  protected final int serverBufSize;

  public MultiTunnelServerFactory(IOStreamFactory serverIOStreamFactory, int serverBufSize) throws IOException {
    this.serverIOStreamFactory = serverIOStreamFactory;
    this.serverBufSize = serverBufSize;
  }

  public void runTunnelServer(IOStream ioTunnel) throws IOException {
    connectTunnelManager(ioTunnel, true);
  }

  protected MultiTunnelSession createSession(int sessionId) throws IOException {
    IOStream ioServer = this.serverIOStreamFactory.open();
    return new MultiTunnelServer(this, sessionId, ioServer, this.serverBufSize);
  }

  // public void runConnector() throws IOException {
  // byte[] buffer = new byte[] { 'C', 'A', 'F', 'E' };
  // writeToTunnel(0, buffer, 0, buffer.length);
  // super.runConnector();
  // }
}
